<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box {
            height: 100px;
            width: 100px;
            background-color: pink;
            position: absolute;
            left: 0;
            top: 0;
        }
    </style>
</head>
<body>
    <div id="box"></div>
    <script>
      document.querySelector('#box').onclick = function () {
          var timer = setInterval (() => {
              //箭头函数没有this，所以这里的this就往上找，所以找到的this就是调用对象，#box
            this.style.top = this.offsetTop + 10 +'px'
            //判断终点
            //this.clientHeight 指的是当前元素的高度，没有单位，
            if (this.offsetTop >=window.innerHeight - this.clientHeight) {
                clearInterval(timer)
                this.style.top = window.innerHeight -this.clientHeight + 'px'
            }
          },20)
      }
    </script>
</body>
</html>